class Solution {
    public static void main(String[] args) {
        System.out.println(isMatch("aa" , "*"));
    }
    public static boolean isMatch(String s, String p) {
            int n = s.length() ;
            int m = p.length() ;
            boolean[][] dp = new boolean[n+1][m+1] ; 
            dp[0][0] = true ;
             s = " "+s ;
             p = " "+p ;
             char[] sArr = s.toCharArray() ;
             char[] pArr = p.toCharArray() ;

        for(int i=1 ;i<=m ; i ++){
            if(dp[0][i-1] && pArr[i] == '*'){
                dp[0][i] = true ;
            }
        }
             for(int i=1 ; i<=n ; i++){
                for(int j=1 ; j <= m ; j++){
                    if(pArr[j]>='a' && pArr[j]<='z'){
                       if(pArr[j] == sArr[i]){
                           dp[i][j]  = dp[i-1][j-1] ; 
                       }
                    }else{
                        if(pArr[j] == '?'){
                           dp[i][j] = dp[i-1][j-1] ; 
                        }else{
                         dp[i][j] = dp[i][j-1] || dp[i-1][j];
                        }
                    }
                }
             }
        return dp[n][m] ; 
    }
}